#include "StdAfx.h"
#include "CylinderEditor.h"
#include "EditorHelper.h"
#include "FunctionDriverCylinder.h"

REGISTERE_EDITOR(CCylinderEditor);

CCylinderEditor::CCylinderEditor(void)
{

}

CCylinderEditor::~CCylinderEditor(void)
{

}
CString CCylinderEditor::GetID(void)
{
	return CYLINDER_GUID;
}

CCylinderInfo* CCylinderEditor::GetShapeInfo()
{
	return &m_Info;
}

void CCylinderEditor::Initialize(CAnyView* pView)
{
	m_Info.Reset();

	AddSubEditor(new CPointCapture(m_Info.ptCenter), 
		CCylinderInfo::CENTER_POINT);
	AddSubEditor(new CLengthCapture(m_Info.ptCenter, m_ptEnd, m_Info.dRadius),
		CCylinderInfo::RADIUS);
	AddSubEditor(new CHeightCapture(m_ptEnd, m_ptHeightEnd, m_Info.dHeight),
		CCylinderInfo::HEIGHT);

	CModelEditor::Initialize(pView);

	m_Info.dir = pView->CurPlaneNormal();
}


bool CCylinderEditor::CreatePreviewShape()
{
	if(CurrentStep() == CCylinderInfo::CENTER_POINT)
		return false;

	TopoDS_Shape shape;
	CCylinderBuilder builder;
	if(builder.Build(&m_Info, shape))
	{
		SetPreviewShape(shape);
		return true;
	}

	return false;

}

bool CCylinderEditor::CreateShapeLabel(TDF_Label& label)
{
	label = NewLabel(_T("Cylinder"));;

	m_Info.AddToLabel(label);

	Handle(CFunctionDriverCylinder) functionDriver;
	return ProcessFunctionDriver<CFunctionDriverCylinder>(label, functionDriver);
}